package simulation;

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * 地图类（全局变量）
 */

public class Map {
    // 共10个抽象宿舍房间，6个抽象教室，3个抽象食堂，1个街道
    public static final ArrayList<Space> spaces = new ArrayList<>(20); // 空间

    public static void initMap() {
        try {
            File map = new File("map.txt");
            Scanner myScanner = new Scanner(map);
            int spaceNo;
            double _up, _down, _left, _right, _posAx, _posAy, _posBx, _posBy;
            while (myScanner.hasNextLine()) {
                spaceNo = myScanner.nextInt();
                _up = myScanner.nextDouble();
                _down = myScanner.nextDouble();
                _left = myScanner.nextDouble();
                _right = myScanner.nextDouble();
                _posAx = myScanner.nextDouble();
                _posAy = myScanner.nextDouble();
                _posBx = myScanner.nextDouble();
                _posBy = myScanner.nextDouble();
                spaces.add(new Space(_up, _down, _left, _right));
                spaces.get(spaceNo).setDoor(new Door(new Position(_posAx, _posAy), new Position(_posBx, _posBy)));
            }
            myScanner.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static ArrayList<Space> getSpaces() {
        return spaces;
    }
}
